/// Creator:      gaoruishan
/// CreatDate:    2025-09-01
/// Description:  患者交接类型
Class CF.NUR.MNISV3.PHOType Extends %Persistent
{

Relationship PHONode As CF.NUR.MNISV3.PHONode [ Cardinality = children, Inverse = PHOType ];

/// 类型名称
Property TypeName As %String(TRUNCATE = 1);

/// 类型Code
Property TypeCode As %String(TRUNCATE = 1);

/// 类型序号
Property TypeSort As %String(TRUNCATE = 1);

/// 院区ID
Property HospId As %String(TRUNCATE = 1);

/// 是否有效
Property ValidFlag As %String(TRUNCATE = 1);

/// 索引  院区ID  +  模板类型
Index Code On (HospId, TypeCode);

/// 保存
/// w ##class(CF.NUR.MNISV3.PHOType).Save("","TypeName|手术^TypeCode|SS^TypeSort|1^HospId|2^")
/// w ##class(CF.NUR.MNISV3.PHOType).Save("","TypeName|转科^TypeCode|ZK^TypeSort|2^HospId|2^")
ClassMethod Save(id, parr)
{
    s tmp=""
    s a=##class(web.DHCMGNurComm).setmoudtmp(parr,.tmp)
    s rw=$O(^CF.NUR.MNISV3.PHOTypeI("Code"," "_tmp("HospId")," "_tmp("TypeCode"),""))
    //q:rw=""&&(id'="") "err:请勿录入重复的模板!"
    i rw'="" s id=rw //更新数据
    if id'=""
    {
        s rec=##class(CF.NUR.MNISV3.PHOType).%OpenId(id)
    }else{
        s rec=##class(CF.NUR.MNISV3.PHOType).%New()
    }
    i $d(tmp("TypeName")) s rec.TypeName=tmp("TypeName")
    i $d(tmp("TypeCode")) s rec.TypeCode=tmp("TypeCode")
    i $d(tmp("TypeSort")) s rec.TypeSort=tmp("TypeSort")
    i $d(tmp("HospId")) s rec.HospId=tmp("HospId")
    i $d(tmp("ValidFlag")) s rec.ValidFlag=tmp("ValidFlag")
    s sc=rec.%Save()
    s id=rec.%Id()
    d rec.%Close()
    q:$$$ISERR(sc) "err:"_$SYSTEM.Status.GetErrorText(sc)
    q id
}

Storage Default
{
<Data name="PHOTypeDefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>TypeName</Value>
</Value>
<Value name="3">
<Value>TypeCode</Value>
</Value>
<Value name="4">
<Value>TypeSort</Value>
</Value>
<Value name="5">
<Value>HospId</Value>
</Value>
<Value name="6">
<Value>ValidFlag</Value>
</Value>
</Data>
<DataLocation>^CF.NUR.MNISV3.PHOTypeD</DataLocation>
<DefaultData>PHOTypeDefaultData</DefaultData>
<IdLocation>^CF.NUR.MNISV3.PHOTypeD</IdLocation>
<IndexLocation>^CF.NUR.MNISV3.PHOTypeI</IndexLocation>
<StreamLocation>^CF.NUR.MNISV3.PHOTypeS</StreamLocation>
<Type>%Storage.Persistent</Type>
}

}
